package com.example.controller;


    @WebServlet("/login")
    public class LoginServlet extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String username = request.getParameter("username");
            String password = request.getParameter("password");

            // 验证逻辑
            User user = userService.login(username, password);
            if (user != null) {
                request.getSession().setAttribute("user", user);
                response.sendRedirect("success.jsp");
            } else {
                request.setAttribute("error", "用户名或密码错误");
                request.getRequestDispatcher("login.jsp").forward(request, response);
            }
        }
    }

